import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const state = {
  currentPageText:'派实',
  searchPopup:false,
  aboutUsOrOurProductsId:'',
  lang:'en',
  productIndexId:0,
  nowPage:'',
  lastCurrentPageText:'',     //上一次浏览的页面
  productInfo:{},     //使用vuex来保存请求过来的产品信息
  links:{},           //友情链接
  linksProduct:{},    //友情链接之我的产品
  linksCompany:{},    //友情链接之公司介绍
  linksContact:{},    //友情链接之联系我们
  searchProduct:{},   //搜索页中前三个产品
  navInfo:{},         //
  productCategory:{}, //商城产品分类
  mallSwipe:{},       //商城轮播图
  mallProductList:{},  //商城分类下的产品包括页码数
  mallProducts:{},     //商城的产品，可加载更多
  nowMallCategoryId:-1,   //当前商城的分类id
  companyNewsList:{},     //新闻列表
  newsId:0,               //新闻详情中的新闻ID
  newsDetails:{},       //新闻详情内容
  searchContent:'',
  loadIngVisible:false,     //加载动画
  isNull:false,
  textIsFocus:false,
  mallActiveId:'#f44',
}

const getters = {
  getTextIsFocus(state){
    return state.textIsFocus;
  },
  getIsNull(state){
    return state.isNull;
  },
  getLoadIngVisible(state){
    return state.loadIngVisible;
  },
  getCurrentPageText(state){
    return state.currentPageText
  },
  getSearchPopup(state){
    return state.searchPopup;
  },
  getAboutUsOrOurProductsId(state){
      return state.aboutUsOrOurProductsId;
  },
  getLang(state){
    return state.lang;
  },
  getProductIndexId(state){
    return state.productIndexId;
  },
  getProductInfo(state){
    return state.productInfo;
  },
  getLinksProduct(state){
    return state.linksProduct;
  },
  getSearchProduct(state){
    return state.searchProduct;
  },
  getNavInfo(state){
    return state.navInfo;
  },
  getLinksCompany(state){
    return state.linksCompany;
  },
  getLinksContact(state){
    return state.linksContact;
  },
  getProductCategory(state){
    return state.productCategory;
  },
  getNowPage(state){
    return state.nowPage;
  },
  getMallSwipe(state){
    return state.mallSwipe;
  },
  getMallProductList(state){
    return state.mallProductList;
  },
  getNowMallCategoryId(state){
    return state.nowMallCategoryId;
  },
  getMallProducts(state){
    return state.mallProducts;
  },
  getCompanyNewsList(state){
    return state.companyNewsList;
  },
  getNewsId(state){
    return state.newsId;
  },
  getNewsDetails(){
    return state.newsDetails;
  },
  getSearchContent(){
    return state.searchContent;
  },
  getLastCurrentPageText(){
    return state.lastCurrentPageText;
  },
  getLinks(){
    return state.links;
  },
  getMallActiveId(){
    return state.mallActiveId;
  }
}

const mutations = {
  changeMallActive(state,item){
    state.mallActiveId=item;
  },
  changeIsNull(state,item){
    state.isNull=item;
  },
  changeLoadIngVisible(state,item){
    state.loadIngVisible=item;
  },
  changeCurrentPageText(state,item){
    state.lastCurrentPageText=state.currentPageText;
    window.sessionStorage.setItem('lastCurrentPageText', state.lastCurrentPageText);
    state.currentPageText=item;
    window.sessionStorage.setItem('currentPageText', state.currentPageText);
  },
  changeSearchPopup(){
    state.searchPopup=!state.searchPopup;
    window.sessionStorage.setItem('searchPopup', state.searchPopup)
  },
  changeAboutUsOrOurProductsId(state,item){
    state.aboutUsOrOurProductsId=item;
    window.sessionStorage.setItem('aboutUsOrOurProductsId', state.aboutUsOrOurProductsId)
  },
  changeLang(state,item){
    state.lang=item;
    window.sessionStorage.setItem('lang', state.lang);
  },
  changeProductIndexId(state,item){
    state.productIndexId=item;
    window.sessionStorage.setItem('productIndexId', state.productIndexId)
  },
  changeProductInfo(state,item){
    state.productInfo=item;
    window.sessionStorage.setItem('productInfo', state.productInfo)
  },
  changeLinksProduct(state,item){
    state.linksProduct=item;
    window.sessionStorage.setItem('linksProduct', state.linksProduct)
  },
  changeSearchProduct(state,item){
    state.searchProduct=item;
    window.sessionStorage.setItem('searchProduct', state.searchProduct)
  },
  changeNavInfo(state,item){
    state.navInfo=item;
    window.sessionStorage.setItem('navInfo', state.navInfo)
  },
  changeLinksCompany(state,item){
    state.linksCompany=item;
    window.sessionStorage.setItem('linksCompany', state.linksCompany)
  },
  changeLinksContact(state,item){
    state.linksContact=item;
    window.sessionStorage.setItem('linksContact', state.linksContact)
  },
  changeProductCategory(state,item){
    state.productCategory=item;
    window.sessionStorage.setItem('productCategory', state.productCategory)
  },
  changeNowPage(state,item){
    state.nowPage=item;
    window.sessionStorage.setItem('nowPage',state.nowPage);
  },
  changeMallSwipe(state,item){
    state.mallSwipe=item;
    window.sessionStorage.setItem('mallSwipe',state.mallSwipe);
  },
  changeMallProductList(state,item){
    state.mallProductList=item;
    window.sessionStorage.setItem('mallProductList',state.mallProductList);
  },
  changeMallProducts(state,item){
    state.mallProducts=item;
    window.sessionStorage.setItem('mallProducts',state.mallProducts);
  },
  addProducts(state,item){
    //let temp=JSON.stringify(JSON.parse(item));
    state.mallProducts=state.mallProducts.concat(item);
    window.sessionStorage.setItem('mallProducts',state.mallProducts);
  },
  changeNowMallCategoryId(state,item){
    state.nowMallCategoryId=item;
    window.sessionStorage.setItem('nowMallCategoryId',state.nowMallCategoryId);
  },
  changeCompanyNewsList(state,item){
    state.companyNewsList=item;
    window.sessionStorage.setItem('companyNewsList',state.companyNewsList);
  },
  addCompanyNewsList(state,item){
    state.companyNewsList=state.companyNewsList.concat(item);
  },
  changeNewsId(state,item){
    state.newsId=item;
    window.sessionStorage.setItem('newsId',state.newsId);
  },
  changeNewsDetails(state,item){
    state.newsDetails=item;
    window.sessionStorage.setItem('newsDetails',state.newsDetails);
  },
  changeSearchContent(state,item){
    state.searchContent=item;
    window.sessionStorage.setItem('searchContent',state.searchContent);
  },
  changeLinks(state,item){
    state.links=item;
    window.sessionStorage.setItem('links',state.links);
  },
  changeTextIsFocus(state,item){
    state.textIsFocus=item;
  }
}

const actions = {
  toChangeMallActive(context,item){
    context.commit('changeMallActive',item);
  },
  toChangeIsNull(context,item){
    context.commit('changeIsNull',item);
  },
  toChangeLoadIngVisible(context,item){
    context.commit('changeLoadIngVisible',item);
  },
  toChangeCurrentPageText(context,item){
    context.commit('changeCurrentPageText',item);
  },
  toChangeSearchPopup(context){
    context.commit('changeSearchPopup');
  },
  toChangeAboutUsOrOurProductsId(context,item){
    context.commit('changeAboutUsOrOurProductsId',item);
  },
  toChangeLang(context,item){
    context.commit('changeLang',item);
  },
  toChangeProductIndexId(context,item){
    context.commit('changeProductIndexId',item);
  },
  toChangeProductInfo(context,item){
    context.commit('changeProductInfo',item);
  },
  toChangeLinksProduct(context,item){
    context.commit('changeLinksProduct',item);
  },
  toChangeSearchProduct(context,item){
    context.commit('changeSearchProduct',item);
  },
  toChangeNavInfo(context,item){
    context.commit('changeNavInfo',item);
  },
  toChangeLinksCompany(context,item){
    context.commit('changeLinksCompany',item);
  },
  toChangeLinksContact(context,item){
    context.commit('changeLinksContact',item);
  },
  toChangeProductCategory(context,item){
    context.commit('changeProductCategory',item);
  },
  toChangeNowPage(context,item){
    context.commit('changeNowPage',item);
  },
  toChangeMallSwipe(context,item){
    context.commit('changeMallSwipe',item);
  },
  toChangeMallProductList(context,item){
    context.commit('changeMallProductList',item);
  },
  toChangeNowMallCategoryId(context,item){
    context.commit('changeNowMallCategoryId',item);
  },
  toChangeMallProducts(context,item){
    context.commit('changeMallProducts',item);
  },
  toAddProducts(context,item){
    context.commit('addProducts',item);
  },
  toChangeCompanyNewsList(context,item){
    context.commit('changeCompanyNewsList',item)
  },
  toAddCompanyNewsList(context,item){
    context.commit('addCompanyNewsList',item);
  },
  toChangeNewsId(context,item){
    context.commit('changeNewsId',item);
  },
  toChangeNewsDetails(context,item){
    context.commit('changeNewsDetails',item);
  },
  toChangeSearchContent(context,item){
    context.commit('changeSearchContent',item);
  },
  toChangeLinks(context,item){
    context.commit('changeLinks',item);
  },
  toChangeTextIsFocus(context,item){
    context.commit('changeTextIsFocus',item);
  }
}
const store = new Vuex.Store({
  state: state,
  getters:getters,
  mutations: mutations,
  actions :actions
})

export default store;
